package com.ymatou.iapi.fundcommission.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fundcommission.service.RefundCommissionRateGetCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtFundDimensionWapper;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.YMTDateUtil;
/**
*返佣费率查询接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RefundCommissionRateGet{
	private static RefundCommissionRateGetCall refundcommissionrategetCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("返佣费率查询接口");
	}

	@Before
	public void caseUp() {
		refundcommissionrategetCall=new RefundCommissionRateGetCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(refundcommissionrategetCall.getOpurl());
	}


	/**
	 * chargecommissionrateget接口返回信息公用错误信息部分断言（正向Case场景）
	 * @throws Exception
	 */	
	public static void refundCommissionRateGetreturncode() throws Exception {
	    try {	    	
			//获取返回报文的数据
			String dataStr = refundcommissionrategetCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");			
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(true, Success, "\"Success\":true");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "Msg等于空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsNull(errCode, "ErrCode等于空");
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body等于空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl等于空");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  

	}
	
	/**
	 * 错误信息断言
	 * @param errcode 错误代码
	 * @param eMsg 错误信息
	 * @throws Exception
	 */
	public void  refundCommissionRateGetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
			String dataStr = refundcommissionrategetCall.getReturnData();
			//返回报文断言			
			String productCommissionList =  new JSONObject(dataStr).getString("OrderRefundCommission");
			Logger.verifyIsNull(productCommissionList, "ProductCommissionList为空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  
	}	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_001() {
		Logger.start(true,"返佣费率查询（新买手-新客）");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "1");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "1");			//新老客户 1新客 2老客
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturncode();
			String dataStr = refundcommissionrategetCall.getReturnData();
			
			//ymt_fundstrategy inner join ymt_fundstrategydimension  查询新买手
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();
	    	Map m1 = new HashMap();
	        m1.put("newold", "1"); //1新 2老
	        m1.put("sellerbuyer", "新老买手");
	        List<Map> fundstdi1 = ymtFundDimensionWapper.selectstrategyforrefund(m1);
	        //断言
			String stid1=(String) fundstdi1.get(0).get("StrategyId");
			Logger.verifyEquals(stid1,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("StrategyId"), "策略Id对比");
			BigDecimal stAmount1= (BigDecimal) fundstdi1.get(0).get("StrategyAmount"); //数据库查询结果
			double stAmountbyapi1=new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getDouble("RefundCommissionRate"); //返回报文结果
			Logger.verifyEquals(stAmount1,  new BigDecimal(stAmountbyapi1).setScale(2,BigDecimal.ROUND_HALF_UP), "策略费率对比");				
			int strategyLevelType=(int) fundstdi1.get(0).get("StrategyLevelType");
			Logger.verifyEquals(strategyLevelType,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getInt("StrategyLevelType"), "策略级别对比");
			//RefundFlag 1老客返佣 2新买手返佣 3常规
			Logger.verifyEquals("2",  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("RefundFlag"), "返佣类型对比");
			String remark=(String) fundstdi1.get(0).get("Remark");
			if (remark == null)
			{
				remark ="null";
			}
			Logger.verifyEquals(remark,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("Remark"), "备注对比");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_002() {
		Logger.start(true,"返佣费率查询（新买手-老客）");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "1");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturncode();
			String dataStr = refundcommissionrategetCall.getReturnData();
			
			//ymt_fundstrategy inner join ymt_fundstrategydimension  查询新买手
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();
	    	Map m2 = new HashMap();
	        m2.put("newold", "2"); //1新 2老
	        m2.put("sellerbuyer", "新老客");
	        List<Map> fundstdi = ymtFundDimensionWapper.selectstrategyforrefund(m2);
	        //断言
			String stid1=(String) fundstdi.get(0).get("StrategyId");
			Logger.verifyEquals(stid1,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("StrategyId"), "策略Id对比");
			BigDecimal stAmount1= (BigDecimal) fundstdi.get(0).get("StrategyAmount"); //数据库查询结果
			double stAmountbyapi1=new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getDouble("RefundCommissionRate"); //返回报文结果
			Logger.verifyEquals(stAmount1,  new BigDecimal(stAmountbyapi1).setScale(2,BigDecimal.ROUND_HALF_UP), "策略费率对比");				
			int strategyLevelType=(int) fundstdi.get(0).get("StrategyLevelType");
			Logger.verifyEquals(strategyLevelType,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getInt("StrategyLevelType"), "策略级别对比");
			//RefundFlag 1老客返佣 2新买手返佣 3常规
			Logger.verifyEquals("1",  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("RefundFlag"), "返佣类型对比");
			String remark=(String) fundstdi.get(0).get("Remark");
			if (remark == null)
			{
				remark ="null";
			}
			Logger.verifyEquals(remark,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("Remark"), "备注对比");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_003() {
		Logger.start(true,"返佣费率查询（老买手-新客）");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "2");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "1");			//新老客户 1新客 2老客
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturncode();
			String dataStr = refundcommissionrategetCall.getReturnData();
			
			//ymt_fundstrategy inner join ymt_fundstrategydimension  查询新买手
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();
	    	Map m1 = new HashMap();
	        m1.put("newold", "2"); //1新 2老
	        m1.put("sellerbuyer", "新老买手");
	        List<Map> fundstdi1 = ymtFundDimensionWapper.selectstrategyforrefund(m1);
	        //断言
			String stid1=(String) fundstdi1.get(0).get("StrategyId");
			Logger.verifyEquals(stid1,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("StrategyId"), "策略Id对比");
			BigDecimal stAmount1= (BigDecimal) fundstdi1.get(0).get("StrategyAmount"); //数据库查询结果
			double stAmountbyapi1=new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getDouble("RefundCommissionRate"); //返回报文结果
			Logger.verifyEquals(stAmount1,  new BigDecimal(stAmountbyapi1).setScale(2,BigDecimal.ROUND_HALF_UP), "策略费率对比");				
			int strategyLevelType=(int) fundstdi1.get(0).get("StrategyLevelType");
			Logger.verifyEquals(strategyLevelType,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getInt("StrategyLevelType"), "策略级别对比");
			//RefundFlag 1老客返佣 2新买手返佣 3常规
			Logger.verifyEquals("3",  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("RefundFlag"), "返佣类型对比");
			String remark=(String) fundstdi1.get(0).get("Remark");
			if (remark == null)
			{
				remark ="null";
			}
			Logger.verifyEquals(remark,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("Remark"), "备注对比");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_004() {
		Logger.start(true,"返佣费率查询（老买手-老客）");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "2");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturncode();
			String dataStr = refundcommissionrategetCall.getReturnData();
			
			//ymt_fundstrategy inner join ymt_fundstrategydimension  查询新买手
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();
	    	Map m2 = new HashMap();
	        m2.put("newold", "2"); //1新 2老
	        m2.put("sellerbuyer", "新老客");
	        List<Map> fundstdi = ymtFundDimensionWapper.selectstrategyforrefund(m2);
	        //断言
			String stid1=(String) fundstdi.get(0).get("StrategyId");
			Logger.verifyEquals(stid1,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("StrategyId"), "策略Id对比");
			BigDecimal stAmount1= (BigDecimal) fundstdi.get(0).get("StrategyAmount"); //数据库查询结果
			double stAmountbyapi1=new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getDouble("RefundCommissionRate"); //返回报文结果
			Logger.verifyEquals(stAmount1,  new BigDecimal(stAmountbyapi1).setScale(2,BigDecimal.ROUND_HALF_UP), "策略费率对比");				
			int strategyLevelType=(int) fundstdi.get(0).get("StrategyLevelType");
			Logger.verifyEquals(strategyLevelType,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getInt("StrategyLevelType"), "策略级别对比");
			//RefundFlag 1老客返佣 2新买手返佣 3常规
			Logger.verifyEquals("1",  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("RefundFlag"), "返佣类型对比");
			String remark=(String) fundstdi.get(0).get("Remark");
			if (remark == null)
			{
				remark ="null";
			}
			Logger.verifyEquals(remark,  new JSONObject(dataStr).getJSONObject("OrderRefundCommission").getString("Remark"), "备注对比");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_005() {
		Logger.start(false,"订单号不能为空");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", null);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "2");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturnerrcode("1001", "订单号不能为空！");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_006() {
		Logger.start(false,"商品买家信息不能为空");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "2");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客
			aa.put("BuyerId", null);			
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturnerrcode("1002", "商品买家卖家信息不能为空！");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_007() {
		Logger.start(false,"商品卖家信息不能为空");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", "2");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客
			aa.put("SellerId", null);			
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturnerrcode("1002", "商品买家卖家信息不能为空！");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_009() {
		Logger.start(false,"新老买手标识不能为空");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("NewSellerFlag", null);			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客		
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturnerrcode("1004", "新老买手标识不能为空!");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RefundCommissionRateGet_010() {
		Logger.start(false,"订单支付时间不能为空");
		try {
			//TODO 补全case代码
			//修改refundCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("LastDatePaid", null);			//业务发生时间
			aa.put("NewSellerFlag", "2");			//新老买手 1新买手 2老买手
			aa.put("NewCustFlag", "2");			//新老客户 1新客 2老客		
			aa.put("CountryId", "0331");		//国家id
			//调用接口json文件
			JSONObject refundCommissionRateGetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/RefundCommissionRateGet.json");
			refundCommissionRateGetBean = JsonBeanHelper.updateJsonBean(refundCommissionRateGetBean, aa);			
			
			refundcommissionrategetCall.setData(refundCommissionRateGetBean);
			refundcommissionrategetCall.callService();			
			refundCommissionRateGetreturnerrcode("1005", "订单支付时间不能为空!");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}